home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / src / fonts.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  2.7 KB  |  116 lines

  1. #include "includes.h"
  2. #include "HTML.h"
  3. #include "mosaic.h"
  4. #include "globals.h"
  5.  
  6. #include <proto/diskfont.h>
  7.  
  8. extern AppData Rdata;
  9.  
  10.  
  11. void setup_font(struct TextAttr *t, char *name, char *pref)
  12. {
  13.   char *p;
  14.   int style = 0;
  15.   int size = 0;
  16.  
  17.   p = strchr(pref, '/');
  18.   if (!p) {
  19.     printf("Malformed fontpref: %s\n", pref);
  20.     exit(1);
  21.   }
  22.   ++p;
  23.   stccpy(name, pref, (p - pref));
  24.   strcat(name, ".font");
  25.  
  26.   size = atoi(p);
  27.  
  28.   if (p = strchr(p, '/')) {    /* look for style */
  29.     p++;
  30.     if (strnicmp(p, "bold", 4) == 0) style |= FSF_BOLD;
  31.     if (strnicmp(p, "italic", 6) == 0) style |= FSF_ITALIC;
  32.   }
  33.  
  34.   t->ta_Name = name;
  35.   t->ta_YSize = size;
  36.   t->ta_Style = style;
  37.   t->ta_Flags = NULL;
  38. }
  39.  
  40.  
  41. void load_font(struct TextFont **f, struct TextAttr *a)
  42. {
  43.   struct TextFont *temp;
  44.  
  45.   *f = OpenDiskFont(a);
  46.   if (!*f) {
  47.     printf("ERROR: no font %s/%d\n", a->ta_Name, a->ta_YSize);
  48.     // WE SHOULD FREE LOTS OF STUFF FIRST!  DUH!
  49.     exit(1);
  50.   }
  51.  
  52.   if ((*f)->tf_Style != a->ta_Style) {
  53.     temp = *f;
  54.     *f = malloc(sizeof(struct TextFont));
  55.     **f = *temp;
  56.     (*f)->tf_Style = a->ta_Style;
  57.   }
  58. }
  59.  
  60.  
  61. /*------------------------------------------------------------------------
  62. ------------------------------------------------------------------------*/
  63. void open_fonts(void)
  64. {
  65.   static char name[15][50];
  66.  
  67.   setup_font(&ta_norm, name[0], Rdata.font);
  68.   setup_font(&ta_fixed, name[1], Rdata.fixedfont);
  69.   setup_font(&ta_h1, name[2], Rdata.h1font);
  70.   setup_font(&ta_h2, name[3], Rdata.h2font);
  71.   setup_font(&ta_h3, name[4], Rdata.h3font);
  72.   setup_font(&ta_h4, name[5], Rdata.h4font);
  73.   setup_font(&ta_h5, name[6], Rdata.h5font);
  74.   setup_font(&ta_h6, name[7], Rdata.h6font);
  75.   setup_font(&ta_bold, name[8], Rdata.boldfont);
  76.   setup_font(&ta_ital, name[9], Rdata.italicfont);
  77.   setup_font(&ta_listing, name[10], Rdata.listingfont);
  78.   setup_font(&ta_plain, name[11], Rdata.plainfont);
  79.   setup_font(&ta_address, name[12], Rdata.addressfont);
  80.  
  81.   load_font(&tf_norm, &ta_norm);
  82.   load_font(&tf_bold, &ta_bold);
  83.   load_font(&tf_ital, &ta_ital);
  84.   load_font(&tf_fixed, &ta_fixed);
  85.   load_font(&tf_h1, &ta_h1);
  86.   load_font(&tf_h2, &ta_h2);
  87.   load_font(&tf_h3, &ta_h3);
  88.   load_font(&tf_h4, &ta_h4);
  89.   load_font(&tf_h5, &ta_h5);
  90.   load_font(&tf_h6, &ta_h6);
  91.   load_font(&tf_listing, &ta_listing);
  92.   load_font(&tf_plain, &ta_plain);
  93.   load_font(&tf_address, &ta_address);
  94. }
  95.  
  96. #define close_font(font) if(font) CloseFont(font);
  97.  
  98. void close_fonts(void)
  99. {
  100.   static char name[15][50];
  101.  
  102.   close_font(tf_norm);
  103.   close_font(tf_bold);
  104.   close_font(tf_ital);
  105.   close_font(tf_fixed);
  106.   close_font(tf_h1);
  107.   close_font(tf_h2);
  108.   close_font(tf_h3);
  109.   close_font(tf_h4);
  110.   close_font(tf_h5);
  111.   close_font(tf_h6);
  112.   close_font(tf_listing);
  113.   close_font(tf_plain);
  114.   close_font(tf_address);
  115. }
  116.